package cn.edu.sdjzu.xg.dao;


import cn.edu.sdjzu.xg.domain.Department;
import cn.edu.sdjzu.xg.domain.Teacher;
import cn.edu.sdjzu.xg.util.JdbcHelper;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class DepartmentDao {
    private static DepartmentDao departmentDao = null;
    private DepartmentDao(){}
    public static DepartmentDao getInstance(){
        if (departmentDao ==null){
            departmentDao =new DepartmentDao();
        }
        return departmentDao;

    }
    public  boolean update(Department department) throws SQLException {
        Connection connection = JdbcHelper.getConn();
        String updateDepartment_sql ="updater department set description =?,no=?,remarks=?,school_id=? where id=?";
        PreparedStatement preparedStatement =connection.prepareStatement(updateDepartment_sql);
        preparedStatement.setString(1,department.getDescription());
        preparedStatement.setString(2,department.getNo());
        preparedStatement.setString(3,department.getRemarks());
        preparedStatement.setInt(4,department.getSchool_id());
        preparedStatement.setInt(5,department.getId());
        int affectedRowNum =preparedStatement.executeUpdate();
        System.out.println("修改了"+affectedRowNum+"条记录");
        JdbcHelper.close(preparedStatement,connection);
        return affectedRowNum>0;
    }
}
